<script>
	export default {
		onLaunch: function() {
			let that = this
			let userInfo = uni.getStorageSync('userInfo')
			let venueId = uni.getStorageSync('venueId')
			let venueName = uni.getStorageSync('venueName')
			if (userInfo) {
				that.$store.commit('saveUserInfo', userInfo);
			} 
			if (venueId) {
				that.$store.commit('setVenueId', venueId);
				that.$store.commit('setVenueName', venueName);
			}
			// #ifdef MP-WEIXIN
			let appId = uni.getAccountInfoSync().miniProgram.appId
			// #endif 
			// #ifdef MP-TOUTIAO
			let appId = uni.getEnvInfoSync().microapp.appId
			// #endif 
			let shopId = 1
			let logo =
				''
			that.$app.ajax({
				data: {
					param: {
						appId
					}
				},
				api: that.$api.getPzobj()
			}).then((resd) => {
				if (resd.record.shopId) {
					shopId = resd.record.shopId
				}
				if (resd.record.logo) {
					logo = resd.record.logo
				}
				that.$store.commit('setShopid', shopId);
				uni.setStorage({
					key: 'logo',
					data: logo
				});
				uni.login({
					// #ifdef MP-WEIXIN
					provider: 'weixin',
					// #endif 
					// #ifdef MP-TOUTIAO
					provider: 'toutiao',
					// #endif 
					success: (loginRes) => {
						that.$app.ajax({
							data: {
								param: {
									code: loginRes.code
								}
							},
							api: that.$api.getUser()
						}).then((res) => {
							that.$store.commit('setOpenId', res.record.openId)
							if (res.record.nickName) {
								that.$store.commit('saveUserInfo', res.record);
							}
							that.$app.ajax({
								data: {
									param: {
										openId: res.record.openId
									}
								},
								api: that.$api.getSessionId()
							}).then((resb) => {
								setTimeout(() => {
									that.$isResolve()
									that.$app.ajax({
										data: {
											param: {}
										},
										api: that.$api.getRenovationInfo()
									}).then((resc) => {
										if (resc.errorCode === '000000' && resc.record) {
										  let val = resc.record || {}
										  that.$store.commit('setColor', val.color1);
										  that.$store.commit('setImgHost', val.path);
										  that.$store.commit('setRenovationInfo', val)
										  let theme = '--color:' + val.color1 + '; --phb:linear-gradient(270deg, ' + val.color1 + ' 0%, ' + val.color2 + ' 100%);' + '--more-color:' + val.color3 + ';--color2:' + val.color2 + ';--blue-bg:linear-gradient(270deg, ' + val.color3 + ' 0%, ' + val.color4 + ' 100%);'
										  that.$store.commit('setTheme', theme);
										  let tabUrl = val.navigationList.map(e=>e.url)
										  that.$store.commit('setTabUrl', tabUrl);
										}
									})
									that.$app.ajax({
										data: {
											param: {
												codes: 'RESOURCE_PATH'
											}
										},
										api: that.$api.getUrl()
									}).then((resc) => {
										that.$store.commit(
											'setOssHost', resc
											.recordList[0]
											.val)
									})
								}, 200)
							})
						}).catch(() => {})
					}
				})

			}).catch(() => {})
		},
		onShow: function() {
			console.log('App Show')
		},
		onHide: function() {
			console.log('App Hide')
		}
	}
</script>

<style lang="scss">
	@import "@/uni_modules/uview-ui/index.scss";
	@import './common/index.scss';
</style>